package com.espirit.eap.manager;

import com.espirit.eap.pagelayout.FunctionButton;
import com.espirit.eap.pagelayout.GridSection;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.eap.sa.User;


public abstract class UserTemplateBuilderSupport extends ModelBuilderSupport {
	public static final String FIELD_NAME="name";
	public static final String FIELD_DEFAULTWEBSITE="defaultWebsite";
	public static final String FIELD_DESCRIPTION="description";
	public static final String FIELD_ID="id";

	FunctionButton apply = null;
	
	protected ModelField mfName;
	protected ModelField mfDescription;
	@Override
	public boolean init() {
		return true;
	}
	
	@Override
	public void buildFields() {
		addModelFieldName("Name", "名称");
		addModelField(FIELD_ID, "Id", "Id");
		
		addModelField(FIELD_DEFAULTWEBSITE, "Default Web Site", "站点");
		addModelField(FIELD_DESCRIPTION, "Description", "描述");
	}
	
	protected void addModelFieldName(String enName,String cnName){
		addModelField(FIELD_NAME, enName, cnName);

	}
	
	@Override
	public void prepareLayoutElements() {
		mfName = getModelField(FIELD_NAME);
		mfDescription = getModelField(FIELD_DESCRIPTION);

		addListField(mfName,mfDescription);
		addDetailField(mfName,mfDescription);
		
		setRequired(FIELD_NAME);
		super.prepareLayoutElements();
	}
	
	protected void setListElementLength(GridSection gridSection ,String fieldName , int length ){
		if (gridSection == null) return ;
		setSearchResultElementWidth(gridSection,fieldName, length);
	}
	
	@Override
	protected void afterBuilderLayout() {
		apply = super.createFunctionButton("apply", "Apply", "Apply", User.class, "apply", true);
		
		updateObject(apply);
		elementService.addSectionElement(getDefaultDetailLayout().createFlatSection(), apply);
		super.afterBuilderLayout();
	}
}
